{"ast":null,"code":"var _jsxFileName = \"/data/messenger.client/src/components/UploadFiles/index.tsx\",\n  _s = $RefreshSig$();\nimport React from 'react';\nimport { Modal, Upload } from 'antd';\nimport './UploadFiles.scss';\nimport mime from \"mime\";\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\nimport { Fragment as _Fragment } from \"react/jsx-dev-runtime\";\nconst getBase64 = file => new Promise((resolve, reject) => {\n  const reader = new FileReader();\n  reader.readAsDataURL(file);\n  reader.onload = () => resolve(reader.result);\n  reader.onerror = error => reject(error);\n});\nconst UploadFiles = _ref => {\n  _s();\n  let {\n    uploaded\n  } = _ref;\n  const [previewOpen, setPreviewOpen] = React.useState(false);\n  const [previewImage, setPreviewImage] = React.useState('');\n  const [previewTitle, setPreviewTitle] = React.useState('');\n  const [fileList, setFileList] = React.useState([{}]);\n  React.useEffect(() => {\n    var _uploaded$items;\n    let tempFileList = [{}];\n    setFileList(tempFileList);\n    if (((_uploaded$items = uploaded.items) === null || _uploaded$items === void 0 ? void 0 : _uploaded$items.length) > 0) {\n      uploaded.items.map((item, index) => {\n        var _mime$getType;\n        if ((_mime$getType = mime.getType(item.link)) !== null && _mime$getType !== void 0 && _mime$getType.includes('image')) {\n          var _item$id;\n          tempFileList[index] = {\n            uid: ((_item$id = item.id) === null || _item$id === void 0 ? void 0 : _item$id.toString()) || '0',\n            status: \"done\",\n            url: process.env.REACT_APP_BACKEND_URL + '/' + item.link,\n            name: (process.env.REACT_APP_BACKEND_URL + '/' + item.link).split('/')[7]\n          };\n        }\n      });\n      setFileList(tempFileList);\n    }\n  }, [uploaded]);\n  const handleCancel = () => setPreviewOpen(false);\n  const handlePreview = async file => {\n    if (!file.url && !file.preview) {\n      file.preview = await getBase64(file.originFileObj);\n    }\n    setPreviewImage(file.url || file.preview);\n    setPreviewOpen(true);\n    setPreviewTitle(file.name || file.url.substring(file.url.lastIndexOf('/') + 1));\n  };\n  const handleChange = _ref2 => {\n    let {\n      fileList: newFileList\n    } = _ref2;\n    console.log(true);\n    //setFileList(newFileList);\n  };\n\n  return /*#__PURE__*/_jsxDEV(_Fragment, {\n    children: fileList && /*#__PURE__*/_jsxDEV(_Fragment, {\n      children: [/*#__PURE__*/_jsxDEV(Upload, {\n        action: \"https://www.mocky.io/v2/5cc8019d300000980a055e76\",\n        listType: \"picture-card\",\n        fileList: fileList,\n        onPreview: handlePreview,\n        onChange: handleChange\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 63,\n        columnNumber: 21\n      }, this), /*#__PURE__*/_jsxDEV(Modal, {\n        open: previewOpen,\n        title: previewTitle,\n        footer: null,\n        onCancel: handleCancel,\n        children: /*#__PURE__*/_jsxDEV(\"img\", {\n          alt: \"example\",\n          style: {\n            width: '100%'\n          },\n          src: previewImage\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 72,\n          columnNumber: 25\n        }, this)\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 71,\n        columnNumber: 21\n      }, this)]\n    }, void 0, true)\n  }, void 0, false);\n};\n_s(UploadFiles, \"ghNHDvTD/8RkReuWwWiQi25lc54=\");\n_c = UploadFiles;\nexport default UploadFiles;\nvar _c;\n$RefreshReg$(_c, \"UploadFiles\");","map":{"version":3,"names":["React","Modal","Upload","mime","getBase64","file","Promise","resolve","reject","reader","FileReader","readAsDataURL","onload","result","onerror","error","UploadFiles","uploaded","previewOpen","setPreviewOpen","useState","previewImage","setPreviewImage","previewTitle","setPreviewTitle","fileList","setFileList","useEffect","tempFileList","items","length","map","item","index","getType","link","includes","uid","id","toString","status","url","process","env","REACT_APP_BACKEND_URL","name","split","handleCancel","handlePreview","preview","originFileObj","substring","lastIndexOf","handleChange","newFileList","console","log","width"],"sources":["/data/messenger.client/src/components/UploadFiles/index.tsx"],"sourcesContent":["import React from 'react';\nimport { Modal, Upload } from 'antd';\nimport type { RcFile, UploadProps } from 'antd/es/upload';\nimport type { UploadFile } from 'antd/es/upload/interface';\nimport {UploadFilesProps} from \"../../models/props/UploadFilesProps\";\nimport './UploadFiles.scss';\nimport mime from \"mime\";\n\nconst getBase64 = (file: RcFile): Promise<string> =>\n    new Promise((resolve, reject) => {\n        const reader = new FileReader();\n        reader.readAsDataURL(file);\n        reader.onload = () => resolve(reader.result as string);\n        reader.onerror = (error) => reject(error);\n    });\n\nconst UploadFiles: React.FC<UploadFilesProps> = ({uploaded}) => {\n    const [previewOpen, setPreviewOpen] = React.useState<boolean>(false);\n    const [previewImage, setPreviewImage] = React.useState('');\n    const [previewTitle, setPreviewTitle] = React.useState('');\n    const [fileList, setFileList] = React.useState<UploadFile[]>([{} as UploadFile]);\n\n    React.useEffect(() => {\n        let tempFileList = [{} as UploadFile];\n        setFileList(tempFileList);\n\n        if (uploaded.items?.length > 0) {\n            uploaded.items.map((item, index) => {\n                if (mime.getType(item.link)?.includes('image')) {\n                    tempFileList[index] = {\n                        uid: item.id?.toString() || '0',\n                        status: \"done\",\n                        url: process.env.REACT_APP_BACKEND_URL + '/' + item.link,\n                        name: (process.env.REACT_APP_BACKEND_URL + '/' + item.link).split('/')[7]\n                    };\n                }\n            });\n            setFileList(tempFileList);\n        }\n    }, [uploaded]);\n\n    const handleCancel = () => setPreviewOpen(false);\n\n    const handlePreview = async (file: UploadFile) => {\n        if (!file.url && !file.preview) {\n            file.preview = await getBase64(file.originFileObj as RcFile);\n        }\n\n        setPreviewImage(file.url || (file.preview as string));\n        setPreviewOpen(true);\n        setPreviewTitle(file.name || file.url!.substring(file.url!.lastIndexOf('/') + 1));\n    };\n\n    const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) => {\n        console.log(true);\n        //setFileList(newFileList);\n    }\n\n    return (\n        <>\n            {fileList && (\n                <>\n                    <Upload\n                        action=\"https://www.mocky.io/v2/5cc8019d300000980a055e76\"\n                        listType=\"picture-card\"\n                        fileList={fileList}\n                        onPreview={handlePreview}\n                        onChange={handleChange}\n                    >\n                    </Upload>\n                    <Modal open={previewOpen} title={previewTitle} footer={null} onCancel={handleCancel}>\n                        <img alt=\"example\" style={{ width: '100%' }} src={previewImage} />\n                    </Modal>\n                </>\n            )\n            }\n        </>\n    );\n};\n\nexport default UploadFiles;"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,KAAK,EAAEC,MAAM,QAAQ,MAAM;AAIpC,OAAO,oBAAoB;AAC3B,OAAOC,IAAI,MAAM,MAAM;AAAC;AAAA;AAExB,MAAMC,SAAS,GAAIC,IAAY,IAC3B,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;EAC7B,MAAMC,MAAM,GAAG,IAAIC,UAAU,EAAE;EAC/BD,MAAM,CAACE,aAAa,CAACN,IAAI,CAAC;EAC1BI,MAAM,CAACG,MAAM,GAAG,MAAML,OAAO,CAACE,MAAM,CAACI,MAAM,CAAW;EACtDJ,MAAM,CAACK,OAAO,GAAIC,KAAK,IAAKP,MAAM,CAACO,KAAK,CAAC;AAC7C,CAAC,CAAC;AAEN,MAAMC,WAAuC,GAAG,QAAgB;EAAA;EAAA,IAAf;IAACC;EAAQ,CAAC;EACvD,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGnB,KAAK,CAACoB,QAAQ,CAAU,KAAK,CAAC;EACpE,MAAM,CAACC,YAAY,EAAEC,eAAe,CAAC,GAAGtB,KAAK,CAACoB,QAAQ,CAAC,EAAE,CAAC;EAC1D,MAAM,CAACG,YAAY,EAAEC,eAAe,CAAC,GAAGxB,KAAK,CAACoB,QAAQ,CAAC,EAAE,CAAC;EAC1D,MAAM,CAACK,QAAQ,EAAEC,WAAW,CAAC,GAAG1B,KAAK,CAACoB,QAAQ,CAAe,CAAC,CAAC,CAAC,CAAe,CAAC;EAEhFpB,KAAK,CAAC2B,SAAS,CAAC,MAAM;IAAA;IAClB,IAAIC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAe;IACrCF,WAAW,CAACE,YAAY,CAAC;IAEzB,IAAI,oBAAAX,QAAQ,CAACY,KAAK,oDAA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